package com.rwx.myjetpack.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.rwx.myjetpack.lifecycle.ILifecycle
import com.rwx.myjetpack.lifecycle.ILifecycleOwner
import com.rwx.myjetpack.lifecycle.LifeState
import com.rwx.myjetpack.lifecycle.LifecycleProvider

/**
 * Created by LH on 2023-05-26.
 * Time: 2023-05-26  14:45
 */
open class BaseActivity :AppCompatActivity(), ILifecycleOwner {

    val lifeProvider by lazy {
        LifecycleProvider()
    }

    override fun getLifecycleProvider(): LifecycleProvider {
        return lifeProvider
    }



    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        lifeProvider.makeLifeState(LifeState.CREATE)

    }


    override fun onStart() {
        super.onStart()
        lifeProvider.makeLifeState(LifeState.START)
    }

    override fun onResume() {
        super.onResume()
        lifeProvider.makeLifeState(LifeState.RESUME)
    }

    override fun onPause() {
        super.onPause()
        lifeProvider.makeLifeState(LifeState.PAUSE)
    }

    override fun onStop() {
        super.onStop()
        lifeProvider.makeLifeState(LifeState.STOP)
    }

    override fun onDestroy() {
        super.onDestroy()
        lifeProvider.makeLifeState(LifeState.DESTORY)
    }


}